﻿Public Class clsPDVINT
    Dim fServidor As String = "", fBanco As String = "", fUsuario As String = "", fSenha As String = ""
    Enum enuTipoBanco
        Access = 0
        MSsql = 1
    End Enum
    Private fMarca As String
    Public Property Marca() As String
        Get
            Return fMarca
        End Get
        Set(ByVal value As String)
            fMarca = value
        End Set
    End Property

    Private fTipoBanco As Byte = 1
    Public Property TipoBanco() As Byte
        Get
            Return fTipoBanco
        End Get
        Set(ByVal value As Byte)
            fTipoBanco = value
        End Set
    End Property

    Private fSede As Boolean = False
    Public Property Sede() As Boolean
        Get
            Return fSede
        End Get
        Set(ByVal value As Boolean)
            fSede = value
        End Set
    End Property

    Public Property Servidor() As String
        Get
            Servidor = fServidor
        End Get
        Set(ByVal ParServidor As String)
            fServidor = ParServidor
        End Set
    End Property
    Public Property Banco() As String
        Get
            Banco = fBanco
        End Get
        Set(ByVal ParBanco As String)
            fBanco = ParBanco
        End Set
    End Property
    Public Property Usuario() As String
        Get
            Usuario = fUsuario
        End Get
        Set(ByVal ParUsuario As String)
            fUsuario = ParUsuario
        End Set
    End Property
    Public Property Senha() As String
        Get
            Senha = fSenha
        End Get
        Set(ByVal parSenha As String)
            fSenha = parSenha
        End Set
    End Property
    Public Function ConnectionString() As String
        Return "Provider=SQLOLEDB.1;Password=" & fSenha & ";Persist Security Info=True;User ID=" & fUsuario & ";Initial Catalog=" & fBanco & ";Data Source=" & fServidor
    End Function

    Public Sub New()
        Dim sArq As String = pDir & "\SQL.INT"
        If Dir(sArq) <> "" Then
            Dim sVet() As String = IO.File.ReadAllLines(sArq)

            For Each sTexto As String In sVet
                Select Case Left(sTexto, 3)
                    Case "SER"
                        fServidor = Mid(sTexto, 5)
                    Case "BAN"
                        fBanco = Mid(sTexto, 5)
                    Case "USU"
                        fUsuario = Mid(sTexto, 5)
                    Case "SEN"
                        fSenha = Descriptografar(Mid(sTexto, 5))
                End Select
            Next
            If fServidor = "" Or fBanco = "" Or fUsuario = "" Then MsgBox("Erro na configuração do arquivo SQL.INT", vbCritical)
        End If

    End Sub
End Class
